package com.bml.architect.spring;

import com.bml.architect.spring.config.AppConfig;
import com.bml.architect.spring.service.User;
import com.bml.architect.spring.service.User1;
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.core.io.Resource;

import java.io.IOException;
import java.util.Locale;

public class Test {

    public static void main(String[] args) throws IOException {

        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
        AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(context);
        reader.register(User1.class);
        ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
        scanner.scan("com.bml.architect.service");

        System.out.println(context.getBean("user1"));

        System.out.println(context.getMessage("title", null, new Locale("en")));
        System.out.println(context.getMessage("title", null, new Locale("zh")));
        System.out.println(context.getMessage("title", null, new Locale("")));

        Resource resource = context.getResource("file://E:\\javaWork\\architect-project\\spring-boot-app\\src\\main\\java\\com\\bml\\architect\\spring\\config\\AppConfig.java");

        System.out.println(resource.exists());
        System.out.println(resource.contentLength());

        Resource resource1 = context.getResource("https://www.baidu.com");
        System.out.println(resource1.contentLength());
        System.out.println(resource1.getURL());

        Resource resource2 = context.getResource("classpath:application.yaml");
        System.out.println(resource2.contentLength());
        System.out.println(resource2.getURL());

        Resource[] resources = context.getResources("classpath:com/bml/architect/spring/*.class");
        for (Resource resource3 : resources) {
            System.out.println(resource3.contentLength());
            System.out.println(resource3.getFilename());
        }
    }


}
